/**
 * @param {number} x
 * @param {number} y
 * @param {number[][]} points
 * @return {number}
 */
export var nearestValidPoint = function (x, y, points) {
  let minDistance = Number.MAX_VALUE
  let ans = -1
  for (let i = 0; i < points.length; i++) {
    const [xi, yi] = points[i]
    if (xi !== x && yi !== y) {
      continue
    }
    const distance = Math.abs(x - xi) + Math.abs(y - yi)
    if (distance < minDistance) {
      minDistance = distance
      ans = i
    }
  }
  return ans
}
